package com.tmt.im.wallet.config;

import com.tmt.im.wallet.config.beans.PayProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.system.SystemProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/10/19 20:20
 * @Version 1.0
 **/
@Slf4j
@Configuration
public class PayConfig {

    private final ApplicationContext applicationContext;

    public PayConfig(ApplicationContext applicationContext){
        this.applicationContext = applicationContext;
    }

    @Bean
    public PayProperties payProperties(){
        Environment environment = applicationContext.getBean(Environment.class);
        String payGateWay = environment.getProperty("PAY_GATEWAY");
        Assert.isTrue(StringUtils.hasText(payGateWay), "未配置支付网关域名参数(PAY_GATEWAY)");

        String mAccount = environment.getProperty("MERCHANT_ACCOUNT");
        Assert.isTrue(StringUtils.hasText(mAccount), "未配置商户账号参数(MERCHANT_ACCOUNT)");

        String mSecretKey = environment.getProperty("MERCHANT_SECRET_KEY");
        Assert.isTrue(StringUtils.hasText(mSecretKey), "未配置商户密钥参数(MERCHANT_SECRET_KEY)");

        return new PayProperties(payGateWay, mAccount, mSecretKey);
    }
}
